/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2023 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/

#include "main.h"
#include "rtthread.h"
//#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define LED1_PIN    GET_PIN(B, 6)
#define LED2_PIN    GET_PIN(E, 3)
#define LED3_PIN    GET_PIN(D, 15)

#define LCD_POWER_PIN            GET_PIN(E, 7)//电源


static rt_device_t serial1;                /* 串口设备句柄 */
static rt_device_t serial2;                /* 串口设备句柄 */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
//uint32_t time;

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/

/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
static struct rt_thread led_thread;
static rt_uint8_t rt_led_thread_stack[1024];

static void led_thread_entry(void *parameter);


/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void) {
    /* USER CODE BEGIN 1 */


//    serial1 = rt_device_find("uart1");
//    serial2 = rt_device_find("uart2");
    rt_pin_mode(LED1_PIN,PIN_MODE_OUTPUT);
    rt_pin_mode(LED2_PIN,PIN_MODE_OUTPUT);
    rt_pin_mode(LED3_PIN,PIN_MODE_OUTPUT);
    rt_pin_mode(LCD_POWER_PIN, PIN_MODE_OUTPUT);

    rt_pin_write(LCD_POWER_PIN, PIN_HIGH);
    /* USER CODE END 1 */

    /* MCU Configuration--------------------------------------------------------*/

    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */



    /* USER CODE END Init */

    /* Configure the system clock */

    /* USER CODE BEGIN SysInit */

    /* USER CODE END SysInit */

    /* Initialize all configured peripherals */


    /* USER CODE BEGIN 2 */
    rt_kprintf("RT-Thread Begin Main!\n");
    rt_thread_init(&led_thread, /* 线程控制块 */
                   "led1", /* 线程名字 */
                   led_thread_entry, /* 线程入口函数 */
                   RT_NULL,
                   &rt_led_thread_stack[0], /* 线程栈起始地址 */
                   sizeof(rt_led_thread_stack), /* 线程栈大小 */
                   20, /* 线程的优先级 */
                   20); /* 线程时间片 */

    rt_thread_startup(&led_thread);
    /* USER CODE END 2 */


}

static void led_thread_entry(void *parameter) {
    while (1) {

//        rt_kprintf("Begin led blink!\n");
        rt_pin_write(LED1_PIN, PIN_HIGH);
        rt_pin_write(LED2_PIN, PIN_HIGH);
        rt_pin_write(LED3_PIN, PIN_HIGH);
        rt_thread_mdelay(500);
        rt_pin_write(LED1_PIN, PIN_LOW);
        rt_pin_write(LED2_PIN, PIN_LOW);
        rt_pin_write(LED3_PIN, PIN_LOW);
        rt_thread_mdelay(500);



    }
}


